/*
 * @Author: 赵成功a 3063126760@qq.com
 * @Date: 2024-12-31 01:35:07
 * @LastEditors: 赵成功a 3063126760@qq.com
 * @LastEditTime: 2024-12-31 02:58:42
 * @FilePath: /linux-learning/12-30/signal
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
#include <signal.h>
#include <cstdio>
#include <iostream>
#include <unistd.h>
#include <signal.h>
using namespace std;
#include <sys/types.h>
#include <signal.h>
/* void Print(int i)
{
    int a=alarm(3);
    cout<<"闹钟还剩下"<<a<<"秒";
    //cout<<"收到了"<<i<<"号信号"<<endl;
}
/*int main()
{

    /* signal(SIGINT, Print);
    while(1)
    {
        cout<<"你好"<<endl;
        sleep(1);
    } */
/*  int a=5;
  int b=a/0;
  cout<<"牛逼"<<endl;
  return 0;
} */

/* int main()
{
    alarm(50);
    signal(SIGALRM, Print);
    while(true)
    {
       cout<<"1"<<endl;
       sleep(1);
    } */
/*     pid_t a;
    int b;
    cout<<"请输入你要发送信号的进程"<<endl;
    cin>>a;
    cout<<"请输入你要发送的信号"<<endl;
    cin>>b;
    kill(a,b); */
// int cnt=5;
/*     while(cnt--)
    {
        cout<<"1"<<endl;
        sleep(1);
    }
    raise(2);
    abort();
    cout<<"天崩了"; */

//} */
void Print(const sigset_t &set)
{
    for (int i = 31; i >= 1; i--)
    {
        if (sigismember(&set, i))cout << "1";
        else   cout << "0";
    }
    cout<<endl;
}
int main()
{
    sigset_t set, oset;
    //sigemptyset(&set);
    sigfillset(&set);
    sigaddset(&set, 4);
    // 阻塞
    sigprocmask(SIG_SETMASK, &set, &oset);
    //
    int cnt=10;
    sigset_t nset;
    sigemptyset(&nset);
    while (cnt--)
    {
        sigpending(&nset);
        Print(nset);
        sleep(1);
    }
    sigprocmask(SIG_SETMASK, &oset, nullptr);
    Print(nset);
}